home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 12 / BBS in a box XII-2.iso / Files II / Prog / N-P / OOP for C.sit / OIC.ƒ / replist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-09  |  2.4 KB  |  121 lines  |  [TEXT/KAHL]

  1. /*    
  2.  *        Replist abstract class
  3.  *
  4.  *            Copyright © John Wainwright 1988
  5.  *
  6.  *    Superclasses:
  7.  *        List
  8.  *
  9.  *    Purpose:
  10.  *        Used as structures that are isomorphic to some nested object
  11.  *        and contain ascii representations of the leaf nodes of that 
  12.  *        object in the leaf nodes of the Replist.
  13.  *
  14.  *    methods:
  15.  *        It inherits all methods from List except repList & print.
  16.  */
  17.  
  18. #include "oic.h"
  19. #include "generics.h"
  20.  
  21. class       Replist;
  22.  
  23. struct replist_i
  24. {
  25.     char    *r_open;        /* open bracket string  */
  26.     char     *r_close;        /* close bracket string */
  27.     char    *r_sep;            /* separator string        */
  28. };
  29. typedef struct replist_i replist_i;
  30.  
  31. /* -------------------- List Instance methods ---------------------------- */
  32.  
  33. static object
  34. _new(self, rl, symbols)
  35.     object                self;
  36.     register replist_i    *rl;
  37.     register struct
  38.     {
  39.         char *open, *close, *sep;
  40.     }                    *symbols;
  41. {
  42.     rl->r_open = symbols->open;
  43.     rl->r_close = symbols->close;
  44.     rl->r_sep = symbols->sep;
  45.     
  46.     return self;
  47. }
  48.  
  49. static
  50. _print(self)
  51.     replist      self;
  52. {
  53.     print_replist(self, 0);
  54.     printf("\n");
  55. }
  56.  
  57. /* ------------------- printing utility functions ------------------------------- */
  58.  
  59. static
  60. print_replist(replist, level)
  61.     register object    replist;
  62.     register int    level;
  63. {
  64.     register object        item;
  65.     register replist_i     *rl = localIVs(replist, replist_i);
  66.     object                seq;
  67.  
  68. /*
  69.     for (seq = sequence(replist); item = next(seq); )
  70.         if (ClassOf(item) == Replist)
  71.         {
  72.             printf("%*s%s", level * 2, "", rl->r_open);
  73.             level += 1;
  74.             for (seq = sequence(replist); item = next(seq); )
  75.             {
  76.                 if (ClassOf(item) == Replist)
  77.                 {
  78.                     printf("\n");
  79.                     print_replist(item, level + 1);
  80.                 }
  81.                 else
  82.                     printf("\n%*s%s", level * 2, "", stringOf(item));
  83.                 
  84.                 if ((int)moreInSeq(seq))
  85.                     printf("%s", rl->r_sep);
  86.             }
  87.             level -= 1;
  88.             printf("\n%*s%s", level * 2, "", rl->r_close);
  89.             
  90.             return;
  91.         }
  92.             
  93.     printf("%*s%s", level * 2, "", rl->r_open);
  94. */
  95.  
  96.     printf("%s", rl->r_open);
  97.     for (seq = sequence(replist); item = next(seq); )
  98.     {
  99.         if (ClassOf(item) == Replist)
  100.             print_replist(item, level + 1);
  101.         else
  102.             printf("%s", stringOf(item));
  103.                 
  104.         if ((int)moreInSeq(seq))
  105.             printf("%s", rl->r_sep);
  106.     }
  107.     printf("%s", rl->r_close);
  108. }
  109.  
  110. /* ------------------- Init the Replist class ------------------------------- */
  111.  
  112. _InitReplist()
  113. {
  114.     Replist = NewClass(sizeof(replist_i), 0, "Replist", List, END);
  115.     AddMethods(Replist,
  116.         newGeneric,            _new,
  117.         printGeneric,         _print,
  118.         END);
  119. }
  120.  
  121.